<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>商品管理</cite></a>
    <a layadmin-event="back">返回列表</a>
    <script type="text/html" template>
      <a><cite> 商品详情 </cite></a>
    </script>
  </div>
</div>

<script type="text/html" template
        lay-url="{{'admin/products/' + layui.router().search.id}}"
        lay-done="layui.data.done(d.data)">
  {{# var data = d.data || {} }}
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">
        作品信息
      </div>
      <div class="layui-card-body">
        <div class="layui-form-item">
          <label class="layui-form-label">所属门店</label>
          <div class="layui-input-inline layui-form-mid layui-word-aux">
            {{data.store ? data.store.name : ''}}
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">发行机构</label>
            <div class="layui-input-inline layui-form-mid layui-word-aux">
              {{data.issuer}}
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">发行账号</label>
            <div class="layui-form-mid layui-word-aux">
              {{data.publisher_account}}
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">作品名称</label>
            <div class="layui-input-inline layui-form-mid layui-word-aux">
              {{data.name}}
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">作品作者</label>
            <div class="layui-form-mid layui-word-aux">
              {{data.author || ''}}
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">许可权利</label>
          <div class="layui-form-mid layui-word-aux">
            {{data.hold_rights}}
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">公示Hash</label>
          <div class="layui-form-mid layui-word-aux">
            {{data.public_hash}}
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">发行地址</label>
          <div class="layui-form-mid layui-word-aux">
            {{data.contract_address}}
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">发行数量</label>
          <div class="layui-form-mid layui-word-aux">
            {{data.issue_count}}
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">封面图片</label>
          <div class="layui-form-mid layui-word-aux">
            <img style="width: 80px" src="{{data.logo_url}}" layadmin-event="imagePreview"/>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">资产凭证</label>
          <div class="layui-form-mid layui-word-aux">
            <img style="width: 80px" src="{{data.asset_image_url}}" layadmin-event="imagePreview"/>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-card">
      <div class="layui-card-header">
        商品信息
      </div>
      <div class="layui-card-body">
        <div class="layui-row">
          <div class="layui-inline">
            <div class="layui-form-item">
              <label class="layui-form-label">商品状态</label>
              <div class="layui-form-mid layui-word-aux layui-input-inline">
                {{# if (data.status.value === 'init') { }}
                <span class="layui-font-gray">{{data.status.description}}</span>
                {{# } }}
                {{# if (data.status.value === 'on_sale') { }}
                <span class="layui-font-green">{{data.status.description}}</span>
                {{# } }}
                {{# if (data.status.value === 'stop') { }}
                <span class="layui-font-red">{{data.status.description}}</span>
                {{# } }}
              </div>
            </div>
          </div>
          <div class="layui-inline">
            <div class="layui-form-item">
              <label class="layui-form-label">所属代理</label>
              <div class="layui-form-mid layui-word-aux layui-input-inline">
                {{data.agent ? data.agent.name : '未指定'}}
              </div>
            </div>

          </div>
        </div>
        <div class="layui-row">
          <div class="layui-inline">
            <div class="layui-form-item">
              <label class="layui-form-label">上架时间</label>
              <div class="layui-form-mid layui-word-aux layui-input-inline">
                {{data.online_time || ''}}
              </div>
            </div>
          </div>
          <div class="layui-inline">
            <div class="layui-form-item">
              <label class="layui-form-label">剩余数量</label>
              <div class="layui-form-mid layui-word-aux layui-input-inline">
                {{data.left_count}}
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-inline">
            <div class="layui-form-item">
              <label class="layui-form-label">销售数量</label>
              <div class="layui-form-mid layui-word-aux layui-input-inline">
                {{data.sales_count}}
              </div>
            </div>
          </div>
          <div class="layui-inline">
            <div class="layui-form-item">
              <label class="layui-form-label">销售单价</label>
              <div class="layui-form-mid layui-word-aux layui-input-inline">
                {{data.display_price}} 元
              </div>
            </div>
          </div>
        </div>
        {{# if (data.intro) { }}
        <div class="layui-form-item">
          <label class="layui-form-label">商品简介</label>
          <div class="layui-form-mid layui-word-aux">
            {{data.intro || ''}}
          </div>
        </div>
        {{# } }}
        {{# if (data.description) { }}
        <div class="layui-form-item">
          <label class="layui-form-label">商品详情</label>
          <div class="layui-input-block">
            <pre style="width: 500px; border: solid 2px grey; padding: 20px">{{data.description}}</pre>
          </div>
        </div>
        {{# } }}
      </div>
    </div>
    <div class="layui-card">
      <div class="layui-card-header">
        作品存证
      </div>
      <div class="layui-card-body">
        <div id="table_product_tokens"></div>
      </div>
    </div>
  </div>
</script>
<script type="text/html" id="tpl_status">
  {{# if(d.status.value === 'failed') { }}
  <span>{{d.status.description}}</span>
  {{# } else { }}
  {{d.status.description}}
  {{# } }}
</script>
<script type="text/html" id="tpl_lock_type">
  {{# if(d.lock_type) { }}
  {{d.lock_type.description}}
  {{# } }}
</script>

<script>
  layui.data.done = function (obj) {
    layui.use([], function () {
      let $ = layui.$
        , table = layui.table

      // 列表查询
      table.render({
        elem: '#table_product_tokens'
        , url: 'admin/products/' + obj.id + '/tokens'
        , page: true
        , cols: [[
          {title: '存证ID', field: 'token_id', minWidth: 200}
          , {title: '锁定类型', templet: '#tpl_lock_type', width: 100, align: "center"}
          , {title: '状态', templet: '#tpl_status', width: 100, align: "center"}
        ]]
      });
    })
  }
</script>
